package com.thon.task.post;

import com.thon.entity.post.Post;
import com.thon.service.post.PostService;
import com.thon.task.AbstractTask;
import com.thon.task.annotation.Task;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * @file RegistEmailTask.java
 * @author thon
 * @email thon.ju@gmail.com
 * @date Jul 10, 2013 9:55:31 AM
 * @description TODO
 */
@Task
public class PostViewCountTask extends AbstractTask {
	private static final Log log = LogFactory.getLog(PostViewCountTask.class);

	@Autowired
	private PostService postService;

	@Override
	protected void doTask(Map<Object, Object> context) throws Exception {
		Integer id = (Integer) context.get("id");
		Post post = postService.getPost(id);
		post.setViewCount(post.getViewCount()==null?0:post.getViewCount()+1);
		postService.savePost(post);
	}
}
